package com.isunland.managesystem.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.NavUtils;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseVolleyActivity;
import com.isunland.managesystem.entity.ProjectCollectOriginal.ProjectCollectContent;

public class DetailProjectCountFragment extends Fragment {
  public static final String EXTRA_CONTENT =
      "com.isunland.managesystem.entity.DetailProjectCountFragment.EXTRA_CONTENT";
  public static final String EXTRA_QUERY =
      "com.isunland.managesystem.entity.DetailProjectCountFragment.EXTRA_QUERY";

  private LinearLayout mLlPmName;
  private LinearLayout mLlCustomer;
  private LinearLayout mLlProjectKind;
  private LinearLayout mLlStages;
  private LinearLayout mLlFinishTime;
  private LinearLayout mLlSignTime;
  private LinearLayout mLlIsCheck;
  private TextView mTvPmName;
  private TextView mTvCustomer;
  private TextView mTvProjectKind;
  private TextView mTvStages;
  private TextView mTvFinishTime;
  private TextView mTvSignTime;
  private TextView mTvIsCheck;
  private TextView mTvProjectNum;
  private ProjectCollectContent content;
  private String queryStr = "";
  private ProjectCountContent queryContent;

  @Override public void onCreate(Bundle savedInstanceState) {
    setHasOptionsMenu(true);
    ((BaseVolleyActivity) getActivity()).getSupportActionBar().setTitle(R.string.detail_project);
    ((BaseVolleyActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    content = (ProjectCollectContent) getArguments().getSerializable(EXTRA_CONTENT);
    queryContent = (ProjectCountContent) getArguments().getSerializable(EXTRA_QUERY);
    //		queryStr=(String) getArguments().getSerializable(EXTRA_QUERY);
    super.onCreate(savedInstanceState);
  }

  @Override public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        if (NavUtils.getParentActivityName(getActivity()) != null) {
          NavUtils.navigateUpFromSameTask(getActivity());
        }
        break;

      default:
        break;
    }
    return super.onOptionsItemSelected(item);
  }

  @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_detail_projectcount, container, false);
    initData(v);
    return v;
  }

  private void initData(View v) {
    mLlPmName = (LinearLayout) v.findViewById(R.id.ll_pmName);
    mLlCustomer = (LinearLayout) v.findViewById(R.id.ll_customer);
    mLlProjectKind = (LinearLayout) v.findViewById(R.id.ll_projectKind);
    mLlStages = (LinearLayout) v.findViewById(R.id.ll_stages);
    mLlFinishTime = (LinearLayout) v.findViewById(R.id.ll_finishTime);
    mLlSignTime = (LinearLayout) v.findViewById(R.id.ll_signTime);
    mLlIsCheck = (LinearLayout) v.findViewById(R.id.ll_isCheck);

    mTvPmName = (TextView) v.findViewById(R.id.tv_pmName);
    mTvCustomer = (TextView) v.findViewById(R.id.tv_customer);
    mTvProjectKind = (TextView) v.findViewById(R.id.tv_projectKind);
    mTvStages = (TextView) v.findViewById(R.id.tv_stages);
    mTvFinishTime = (TextView) v.findViewById(R.id.tv_finishTime);
    mTvSignTime = (TextView) v.findViewById(R.id.tv_signDate);
    mTvIsCheck = (TextView) v.findViewById(R.id.tv_isCheck);
    mTvProjectNum = (TextView) v.findViewById(R.id.tv_projectNum);

    if (TextUtils.isEmpty(queryContent.getPmName())) {
      mLlPmName.setVisibility(View.GONE);
    } else {
      mTvPmName.setText(content.getPmName());
    }
    if (TextUtils.isEmpty(queryContent.getPartaName())) {
      mLlCustomer.setVisibility(View.GONE);
    } else {
      mTvCustomer.setText(content.getPartaName());
    }
    if (TextUtils.isEmpty(queryContent.getProjectKindName())) {
      mLlProjectKind.setVisibility(View.GONE);
    } else {
      mTvProjectKind.setText(content.getProjectKindName());
    }
    if (TextUtils.isEmpty(queryContent.getStages())) {
      mLlStages.setVisibility(View.GONE);
    } else {
      mTvStages.setText(content.getStages());
    }
    if (TextUtils.isEmpty(queryContent.getRequireDate())) {
      mLlFinishTime.setVisibility(View.GONE);
    } else {
      mTvFinishTime.setText(content.getRequireDate());
    }
    if (TextUtils.isEmpty(queryContent.getProjectSignDate())) {
      mLlSignTime.setVisibility(View.GONE);
    } else {
      mTvSignTime.setText(content.getProjectSignDate());
    }
    if (TextUtils.isEmpty(queryContent.getIfAcceptance())) {
      mLlIsCheck.setVisibility(View.GONE);
    } else {
      if ("F".equals(content.getIfAcceptance())) {
        mTvIsCheck.setText("未验收");
      } else if ("T".equals(content.getIfAcceptance())) {
        mTvIsCheck.setText("已验收");
      }
    }

    mTvProjectNum.setText(content.getRemark());
  }

  public static DetailProjectCountFragment newInstance(ProjectCollectContent item) {
    Bundle args = new Bundle();
    args.putSerializable(EXTRA_CONTENT, item);
    DetailProjectCountFragment fragment = new DetailProjectCountFragment();
    fragment.setArguments(args);
    return fragment;
  }

  public static DetailProjectCountFragment newInstance(ProjectCollectContent item, String str) {
    Bundle args = new Bundle();
    args.putSerializable(EXTRA_CONTENT, item);
    args.putSerializable(EXTRA_QUERY, str);
    DetailProjectCountFragment fragment = new DetailProjectCountFragment();
    fragment.setArguments(args);
    return fragment;
  }

  public static DetailProjectCountFragment newInstance(ProjectCollectContent item,
      ProjectCountContent queryContent) {
    Bundle args = new Bundle();
    args.putSerializable(EXTRA_CONTENT, item);
    args.putSerializable(EXTRA_QUERY, queryContent);
    DetailProjectCountFragment fragment = new DetailProjectCountFragment();
    fragment.setArguments(args);
    return fragment;
  }
}
